@extends('admin.layouts')
@section('main')
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="id" data-params='{"url": "{{url('admin/roledel')}}","method":"post","data":"_token={{csrf_token()}}","confirm":"true","confirmTest":{"title":"{{trans('config.message')}}","msg":"{{trans('config.btn_text_delete')}}","btn":["{{trans('config.yes')}}","{{trans('config.no')}}"]} }'>
                            <i class="iconfont">&#xe626;</i> {{trans('config.btn_delete')}}
                        </button>
                        <button class="layui-btn layui-btn-small modal-catch" data-params='{"content":".add-subcat", "title":"{{trans('config.add_role')}}","area":"600px,385px","type":"1","shadeClose":1}'>
                            <i class="iconfont">&#xe649;</i> {{trans('config.btn_add')}}
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>

    <div class="add-subcat">
        <form id="form1" class="layui-form layui-form-pane" action="{{url('admin/roleadd')}}">
        {{csrf_field()}}
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('config.role')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required jq-verify="required" jq-error="{{trans('config.vali_required')}}" placeholder="{{trans('config.input_role')}}" autocomplete="off" class="layui-input ">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{trans('config.display_name')}}</label>
            <div class="layui-input-inline">
                <input type="text" name="display_name" placeholder="{{trans('config.input_display_name')}}" autocomplete="off" class="layui-input ">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline" style="width:100%">
                <textarea type="text" name="description" placeholder="{{trans('config.text_description')}}" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" jq-submit jq-filter="submit">{{trans('config.btn_submit')}}</button>
                <button type="reset" class="layui-btn layui-btn-primary">{{trans('config.btn_reset')}}</button>
            </div>
        </div>
        </form>
    </div>
@endsection

@section('script')

<script id="list-tpl" type="text/html" data-params='{"url":"{{url('admin/rolelist')}}","method":"post","data":{"_token":"{{csrf_token()}}"},"pageid":"#page"}'>
    <table id="example" class="layui-table lay-even">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="id" lay-filter="check" lay-skin="primary"></th>
            <th width="60">ID</th>
            <th>角色</th>
            <th>描述</th>
            <th width="80">状态</th>
            <th width="200">操作</th>
        </tr>
        </thead>
        <tbody>
        <{# layui.each(d.list, function(index, item){ }>
        <tr>
            <td><input type="checkbox" name="id" value="<{item.id}>" lay-skin="primary"></td>
            <td><{item.id}></td>
            <td><{item.name}></td>
            <td><{item.description}></td>
            <td><input type="checkbox" name="status" value="<{item.status}>" <{# if(item.status==1){ }>checked<{# } }> lay-skin="switch" lay-text="{{trans('config.btn_enable')}}|{{trans('config.btn_disable')}}" lay-filter="ajax" data-params='{"url":"{{url('admin/roleedit')}}","data":"id=<{item.id}>&_token={{csrf_token()}}" }'> </td>
            <td>
                <button class="layui-btn layui-btn-mini layui-btn-normal modal-iframe" data-params='{"content": "{{url('admin/roleset')}}?id=<{item.id}>","full":"true", "title": "{{trans('config.set_role')}}","type":"1","shadeClose":1}'>
                    <i class="layui-icon">&#x1005;</i>{{trans('config.btn_set')}}
                </button>
                <button class="layui-btn layui-btn-mini modal-iframe" data-params='{"content": "{{url('admin/roleedit')}}?id=<{item.id}>","area":"600px,385px", "title": "{{trans('config.edit_role')}}","type":"1","shadeClose":1}'>
                    <i class="iconfont">&#xe653;</i>{{trans('config.btn_edit')}}
                </button>
                <button class="layui-btn layui-btn-mini layui-btn-danger" data-method="del" data-url="{{url('admin/roledel')}}" data-id="<{item.id}>">
                    <i class="iconfont">&#xe626;</i>{{trans('config.btn_delete')}}
                </button></td>
            </td>
        </tr>
        <{# }); }>
        </tbody>

    </table>
</script>



<script>
layui.use(['list','jquery'],function(){
    var $= layui.jquery;
    $(document).on('click','.layui-btn', function(){
        var othis = $(this), method = othis.data('method');
        active[method] ? active[method].call(this, othis) : '';
    });
    var active={
        del:function(othis){
            var url=$(othis).attr('data-url');
            var id=$(othis).attr('data-id');
            var yesTest="{{trans('config.yes')}}";
            var noTest="{{trans('config.no')}}";
            layer.confirm("{{trans('config.btn_text_delete')}}", {icon: 3, title:"{{trans('config.message')}}"
                ,btn: [yesTest,noTest]
            }, function(){
                $.ajax({
                    url:url,
                    type:"post",
                    data:{"id":id,"_token":"{{csrf_token()}}"},
                    beforeSend:function(){
                        layer.load(1);
                    },
                    success:function(data){
                        if(data.status==200){
                            layer.msg("{{trans('config.submit_success')}}");
                            location.reload();
                        }else{
                            layer.msg("{{trans('config.submit_error')}}");
                        }
                    },
                    complete:function(){
                        layer.closeAll('loading');
                    },
                    error:function(){
                        layer.msg("{{trans('config.net_error')}}");
                    }
                })
            }, function(){
            });
        }
    }
})
</script>
@endsection